package com.ruoyi.web.controller.system;

import com.github.jaemon.dinger.core.entity.DingerResponse;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AccountDeposit;
import com.ruoyi.system.service.IAccountDepositService;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.web.core.config.CustomDinger;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * 存入Controller
 * 
 * @author ruoyi
 * @date 2024-03-07
 */
@Controller
@RequestMapping("/system/deposit")
public class AccountDepositController extends BaseController
{
    private String prefix = "system/deposit";

    @Autowired
    private IAccountDepositService accountDepositService;
    @Autowired
    private ISysConfigService iSysConfigService;
    @Autowired
    private CustomDinger customDinger;

    @RequiresPermissions("system:deposit:view")
    @GetMapping()
    public String deposit()
    {
        return prefix + "/deposit";
    }

    /**
     * 查询存入列表
     */
    @RequiresPermissions("system:deposit:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AccountDeposit accountDeposit)
    {
        startPage();
        List<AccountDeposit> list = accountDepositService.selectAccountDepositList(accountDeposit);
        return getDataTable(list);
    }

    /**
     * 导出存入列表
     */
    @RequiresPermissions("system:deposit:export")
    @Log(title = "存入", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AccountDeposit accountDeposit)
    {
        List<AccountDeposit> list = accountDepositService.selectAccountDepositList(accountDeposit);
        ExcelUtil<AccountDeposit> util = new ExcelUtil<AccountDeposit>(AccountDeposit.class);
        return util.exportExcel(list, "存入数据");
    }

    /**
     * 新增存入
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存存入
     */
    @RequiresPermissions("system:deposit:add")
    @Log(title = "存入", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AccountDeposit accountDeposit)
    {
        accountDeposit.setCreateTime(DateUtils.getNowDate());
        return toAjax(accountDepositService.insertAccountDeposit(accountDeposit));
    }

    /**
     * 新增保存存入
     */
    @PostMapping("/outAdd")
    @ResponseBody
    public AjaxResult outAdd(AccountDeposit accountDeposit,String tgcg)
    {
        accountDeposit.setCreateTime(DateUtils.getNowDate());
        AjaxResult ajax =AjaxResult.success();
        if(StringUtils.isBlank(tgcg)){
            ajax=toAjax(accountDepositService.insertAccountDeposit(accountDeposit));
            String s = iSysConfigService.selectConfigByKey("bank_card");
            ajax.put("info",s);
        }
      //  if(StringUtils.isNotEmpty(tgcg)){
            DingerResponse in = customDinger.in(accountDeposit.getDepositAccount(), accountDeposit.getDepositAmount());
            System.out.println(in);
      //  }

        return ajax;
    }

   @GetMapping("/ddddtest")
    public void test(){
        DingerResponse in = customDinger.in("test", "xxxxxx");
        System.out.println(in);
    }

    /**
     * 修改存入
     */
    @RequiresPermissions("system:deposit:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AccountDeposit accountDeposit = accountDepositService.selectAccountDepositById(id);
        mmap.put("accountDeposit", accountDeposit);
        return prefix + "/edit";
    }

    /**
     * 修改保存存入
     */
    @RequiresPermissions("system:deposit:edit")
    @Log(title = "存入", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AccountDeposit accountDeposit)
    {
        return toAjax(accountDepositService.updateAccountDeposit(accountDeposit));
    }

    /**
     * 删除存入
     */
    @RequiresPermissions("system:deposit:remove")
    @Log(title = "存入", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(accountDepositService.deleteAccountDepositByIds(ids));
    }

    @Log(title = "处理", businessType = BusinessType.OTHER)
    @PostMapping( "/deal")
    @ResponseBody
    public AjaxResult deal(String id)
    {
        AccountDeposit temp = new AccountDeposit();
        temp.setId(Long.parseLong(id));
        temp.setStatus(1);
        return toAjax(accountDepositService.updateAccountDeposit(temp));
    }
}
